package com.yuanzhy.tools.commons.pool;

import org.apache.commons.pool2.BaseKeyedPooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;

import java.util.concurrent.ThreadLocalRandom;

public class ComplexKeyedPooledObjectFactory extends BaseKeyedPooledObjectFactory<MyKey, ComplexObject> {

    @Override
    public ComplexObject create(MyKey key) {
        String name = "test" + ThreadLocalRandom.current().nextInt(100);
        return new ComplexObject(name);
    }

    @Override
    public PooledObject<ComplexObject> wrap(ComplexObject value) {
        return new DefaultPooledObject<>(value);
    }
}
